<template>
	<view>
		<u-steps current="0" direction="column">
			<u-steps-item v-for="(item, index) in browseRecords"
				:title="'查看了 -' + (item.giName || item.gbPage) + ' - 浏览时长： ' + parseInt(item.gbTime / 1000) + '秒'"
				:desc="UTCTimeToLocal(item.gbInti)">
			</u-steps-item>
		</u-steps>

		<view v-if="isShow===true" style="text-align: center;color: #C0C0C0;">数据加载完毕！</view>
	</view>
</template>

<script>
	import {
		getCustomerBrowse
	} from "../../utils/api.js";
	import {
		mapGetters
	} from "vuex";

	export default {
		data() {
			return {
				browseRecords: [],
				ciUuid: "",
				pageSize: 20,
				page: 1,
				totalCount: 0,
				isloading: false,
				isShow: false
			};
		},

		computed: {
			...mapGetters({
				activity: "activityInfo/activity"
			}),
		},

		onLoad(params) {
			this.ciUuid = params.ciUuid;
			if (params.ciUuid) {
				this.loadCustBrowse(this.ciUuid, this.activity.gpUuid);
			}
		},

		watch: {},

		//监听页面上拉触底行为
		onReachBottom() {
			if (this.page * this.pageSize >= this.totalCount) {
				this.isShow = true
				return
			}
			if (this.isloading) return
			this.page += 1
			this.loadCustBrowse(this.ciUuid, this.activity.gpUuid)
		},

		methods: {
			async loadCustBrowse(ciUuid, gpUuid) {
				this.isloading = true
				let res = await getCustomerBrowse({
					ciUuid,
					gpUuid,
					first: this.pageSize,
					offset: (this.page - 1) * this.pageSize
				});
				console.log(res)
				if (res) {
					this.isloading = false
					this.browseRecords = [...this.browseRecords, ...res.nodes] || [];
					this.totalCount = res.totalCount
				}
			},
		},
	};
</script>

<style lang="scss" scoped>
	page {
		height: 100%
	}
</style>
